package com.example.barcodeapp.ui.huodong;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.barcodeapp.R;
import com.example.barcodeapp.base.BaseFragment;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.interfaces.IBasePersenter;
import com.example.barcodeapp.interfaces.own.IOwn;
import com.example.barcodeapp.persenter.OnePresenterHuoDong;
import com.example.barcodeapp.ui.huodong.activity.HuoDongXiangQingActivity;
import com.example.barcodeapp.ui.own.activity.QueRenActivity;
import com.example.barcodeapp.ui.own.activity.ZhiFuActivity;
import com.example.barcodeapp.ui.own.bean.HuoDongBean;
import com.lljjcoder.citypickerview.widget.CityPicker;
import com.youth.banner.Banner;

import butterknife.BindView;


public class FragmentHuoDong extends BaseFragment<IOwn.Persenterkechenghuodong> implements IOwn.Viewkechenghuodong {


    @BindView(R.id.shurusousuo)
    EditText shurusousuo;
    @BindView(R.id.toobar_loge_news)
    RelativeLayout toobarLogeNews;
    @BindView(R.id.huodong_banner)
    Banner huodongBanner;
    @BindView(R.id.jieshaowenzi)
    TextView jieshaowenzi;
    @BindView(R.id.jieshao_gengduo)
    TextView jieshaoGengduo;
    @BindView(R.id.huodongneirong)
    RecyclerView huodongneirong;
    @BindView(R.id.constraintLayout)
    ConstraintLayout constraintLayout;
    @BindView(R.id.huodongwenzi)
    TextView huodongwenzi;
    @BindView(R.id.huodongleibiaoneirong)
    RecyclerView huodongleibiaoneirong;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    private CityPicker mCP;

    @Override
    protected int getLayout() {
        return R.layout.fragment_huo_dong;
    }

    @Override
    protected void initView() {
    }

    @Override
    protected OnePresenterHuoDong initPersenter() {
        return new OnePresenterHuoDong();
    }


    @Override
    protected void initData() {
        persenter.getKeChengHuoDong(1);
    }

    @Override
    public void getKeChengHuoDong(HuoDongBean xiLieKeBean) {

        AdapterZuiXin adapterJiangShi = new AdapterZuiXin(getActivity(),xiLieKeBean.getData());
        LinearLayoutManager manager = new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        huodongneirong.setLayoutManager(manager);
        huodongneirong.setAdapter(adapterJiangShi);
        AdapterLeiBiao adapterJiangShi2 = new AdapterLeiBiao(getActivity(),xiLieKeBean.getData());
        huodongleibiaoneirong.setLayoutManager(new LinearLayoutManager(getActivity()));

        huodongleibiaoneirong.setAdapter(adapterJiangShi2);
        adapterJiangShi.setClick (new AdapterZuiXin.IClick() {
            @Override
            public void click(int pos) {
                Constants.huodongxiangqingid=xiLieKeBean.getData().get(pos).getId();
                Intent instant = new Intent(getActivity(), HuoDongXiangQingActivity.class);
//            instant.putExtra("data","系列课程");
                startActivity(instant);
            }
        });
        adapterJiangShi2.setCallback(new AdapterLeiBiao.IClick() {
            @Override
            public void click(int pos) {
                Constants.huodongxiangqingid=xiLieKeBean.getData().get(pos).getId();
                Intent instant = new Intent(getActivity(), HuoDongXiangQingActivity.class);
                startActivity(instant);
            }
        });

        tvAddress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mYunCityPicher();
                mCP.show();
            }
        });
    }
    public void mYunCityPicher() {
        mCP = new CityPicker.Builder(getActivity())
                .textSize(20)
                //地址选择
                .title("地址选择")
                .backgroundPop(0xa0000000)
                //文字的颜色
                .titleBackgroundColor("#0CB6CA")
                .titleTextColor("#000000")
                .backgroundPop(0xa0000000)
                .confirTextColor("#000000")
                .cancelTextColor("#000000")
                .province("xx省")
                .city("xx市")
                .district("xx区")
                //滑轮文字的颜色
                .textColor(Color.parseColor("#000000"))
                //省滑轮是否循环显示
                .provinceCyclic(true)
                //市滑轮是否循环显示
                .cityCyclic(false)
                //地区（县）滑轮是否循环显示
                .districtCyclic(false)
                //滑轮显示的item个数
                .visibleItemsCount(7)
                //滑轮item间距
                .itemPadding(10)
                .onlyShowProvinceAndCity(false)
                .build();

        //监听
        mCP.setOnCityItemClickListener(new CityPicker.OnCityItemClickListener() {
            @Override
            public void onSelected(String... citySelected) {
                //省
                String province = citySelected[0];
                //市
                String city = citySelected[1];
                //区。县。（两级联动，必须返回空）
                String district = citySelected[2];
                //邮证编码
                String code = citySelected[3];
                tvAddress.setText(province + city + district);
            }

            @Override
            public void onCancel() {


            }
        });
    }
}